package com.example.testanimation.graphics.matrix.color;

import android.graphics.*;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import com.example.testanimation.R;
import com.lenovo.nova.util.BaseActivity;
import com.lenovo.nova.widget.baseview.GridEditView;

/**
 * Created by scenic on 2015/3/28.
 */
public class CustomColorMatrixTestActivity extends BaseActivity {

    private Bitmap bitmap;
    private ImageView mImageView;
    private GridEditView mGirdLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_matrix_custom_color_image);
        bitmap = BitmapFactory.decodeResource(getResources(),
                R.drawable.jpg_test);
        mImageView = (ImageView)findViewById(R.id.imageView1);
//        mImageView.setImageBitmap(ImageColorUtils.handlerImageOld(bitmap));
        mGirdLayout = (GridEditView)findViewById(R.id.id_gridview);
    }

    public void btnChange(View view) {
        Bitmap tmpBmp = Bitmap.createBitmap( bitmap.getWidth(),
                bitmap.getHeight(), Bitmap.Config.ARGB_8888);

        ColorMatrix colorMatrix = new ColorMatrix();
        float[] mColorMatrix = mGirdLayout.getValues();
        colorMatrix.set(mColorMatrix);

        Canvas canvas = new Canvas(tmpBmp);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
        canvas.drawBitmap(bitmap,0,0,paint);
        mImageView.setImageBitmap(tmpBmp);
    }




}
